package com.icode.cas.spinLock;

import java.util.concurrent.TimeUnit;

/**
 * @Author: my_code
 * @Email: my_code@foxmail.com
 * @Create: 2020-12-14 19:13
 */
public class TestSpinLock {

    public static void main(String[] args) {

        SpinLock spinLock = new SpinLock();

        new Thread(() -> {
            spinLock.myLock();
            try {
                System.out.println("111111111");
                TimeUnit.SECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
            spinLock.myUnLock();
            }

        }, "T1").start();
        //延时几秒
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            spinLock.myLock();
            try {
                System.out.println("222222222");
            } finally {
                spinLock.myUnLock();
            }
        }, "T2").start();
    }
}
